do
    -- use pin 1 as the input pulse width counter
    local pin=6
    gpio.mode(pin,gpio.OUTPUT)

    -- pin=4,gpio2 led
    local echo, rsec, rusec, trig = 5, 0, 0, gpio.trig
    gpio.mode(echo, gpio.INT)
    local function pin1cb(level)
        if(level == gpio.HIGH) then
            rsec, rusec=rtctime.get()
        end
        if(level == gpio.LOW) then
            local nrsec,nrusec = 0,0
            nrsec,nrusec=rtctime.get()
            print(nrsec - rsec,nrusec-rusec,(nrusec-rusec)/1000000*340/2)
        end
        trig(echo, level == gpio.HIGH and "down" or "up")
    end
    trig(echo, "up", pin1cb)

    tmr.alarm(1, 2000, 1, function()
       gpio.write(pin,gpio.HIGH)
       gpio.write(pin,gpio.LOW)
       --gpio.write(echo,gpio.HIGH)
    end )
end
